<<<<<<< HEAD
function HmiWebSocket()
{
	this.serverip = "";
	this.serverport = "";
	this.connectstate = 0;
	var wsUri = "";
    var websocket = null;
    var objthis = this;
    this.cusdebug=function(msg){
        
        
        
        $("#serverLayoutTop").text(msg);

        if(msg==="Connected"){
            connectstate = 1;
=======
/*定时器实例
 * window.setInterval(getPic, 100);
        function getPic(){                
            $("#page_process_m_open_list_n").attr('src',"${pageContext.request.contextPath}/img/home_n.png?time="+(new Date()).getTime());            

        };*/

function HmiWebSocket()
{
    this.serverip = "";
    this.serverport = "";
    this.connectstate = 0;
    this.isConnectedOnce = 0;      //连接上过一次
    this.connectFaildStatistics=0; //连接失败次数
    var wsUri = "";
    var websocket = null;
    var objthis = this;
    
    this.cusdebug=function(msg){
        
        $("#serverLayoutTop").text(msg);

        if(msg==="Connected"){
            this.connectstate = 1;
            this.isConnectedOnce = 1;
            
            $("#modle_bt_login_msg").text("连接服务器成功");
        }
        else if(msg==="DISCONNECTED")
        {
            websocket.close();
            //当前用户 重新登陆
            var connectCount = this.connectFaildStatistics+1;
            $("#modle_bt_login_msg").text("服务器连接已经断开正在尝试第 "+connectCount+" 次连接"+"....");
            if(this.isConnectedOnce === 1)
            {
                window.location.reload();
            }
            else
            {
                this.connectFaildStatistics++;
                this.initWebSocket();
            }
            
>>>>>>> dev
        }
        /*
        var recvMsg = msg;
        var jsonObject = JSON.parse(recvMsg);
        if( typeof(jsonObject.response_battery_info) != "undefined")
        {
            if(typeof(jsonObject.response_battery_info.lightmode) != "undefined")
            {
                var value_light=jsonObject.response_battery_info.lightmode*100;
                $("#serverLayoutTop").text(jsonObject.response_battery_info.lightmode);
                $("#pop_battery_info").text(value_light);
                
            }
        }
        */
<<<<<<< HEAD

        //接收数据处理
        objGlobalVariable.objCusUpdateTopState.responseTopState(msg);
=======
        //接收数据处理
        window.objGlobalManage.objCusUpdateTopState.responseTopState(msg);
>>>>>>> dev
    };
    
    this.setServerIpPort=function(ip,port){
    	this.serverip=ip;
    	this.serverport=port;
        wsUri = "ws://"+ip+":"+port;
<<<<<<< HEAD
        
        
    };
    
	this.sendMessage=function(msg) {
            
        if ( websocket != null && connectstate===1)
        {
=======
    };
	this.sendMessage=function(msg) {  
        if ( websocket != null && this.connectstate===1)
        { 
>>>>>>> dev
            websocket.send( msg );
        }
    };
    this.initWebSocket=function() {
        try {
<<<<<<< HEAD
            if (typeof MozWebSocket == 'function')
=======
            if (typeof MozWebSocket === 'function')
>>>>>>> dev
            {
            	WebSocket = MozWebSocket;
            }
            if ( websocket && websocket.readyState == 1 )
            {
            	websocket.close();
            }
                
<<<<<<< HEAD
            websocket = new WebSocket( wsUri );
=======
            if(websocket !== null)
            {
                websocket=null;
                       
                
            }
            websocket = new WebSocket( wsUri );
            
>>>>>>> dev

            websocket.onopen = function (evt) {
                objthis.cusdebug("Connected");
            };
            websocket.onclose = function (evt) {
                objthis.cusdebug("DISCONNECTED");
<<<<<<< HEAD
                connectstate = 0;
            };
            websocket.onmessage = function (evt) {
                console.log( "Message received :", evt.data );
=======
                this.connectstate = 0;
            };
            websocket.onmessage = function (evt) {
>>>>>>> dev
                objthis.cusdebug( evt.data );
            };
            websocket.onerror = function (evt) {
                objthis.cusdebug('ERROR: ' + evt.data);
            };

<<<<<<< HEAD
            
=======
>>>>>>> dev
        } catch (exception) {
            objthis.cusdebug('ERROR: ' + exception);
        }
    };
<<<<<<< HEAD
=======

>>>>>>> dev
    this.stopWebSocket= function() {
        if (websocket)
            websocket.close();
    };
    this.checkSocket=function() {
        if (websocket != null) {
            var stateStr;
            switch (websocket.readyState) {
                case 0: {
                    stateStr = "CONNECTING";
                    break;
                }
                case 1: {
                    stateStr = "OPEN";
                    break;
                }
                case 2: {
                    stateStr = "CLOSING";
                    break;
                }
                case 3: {
                    stateStr = "CLOSED";
                    break;
                }
                default: {
                    stateStr = "UNKNOW";
                    break;
                }
            }
            objthis.cusdebug("WebSocket state = " + websocket.readyState + " ( " + stateStr + " )");
        } else {
            objthis.cusdebug("WebSocket is null");
        }
    };
}

            
